{extend name="base"/}
{block name="resources"}
<link rel="stylesheet" href="SHOP_SUPPLY_LOCAL_CSS/order.css">
{/block}
{block name="body"}
<!-- 顶部html文件-->
<div class="ns-supply-wrap">
	<div class="ns-supply-wrap-con">
		{include file="addon/supply/shop/view/market_head.html"/}

		<div class="ns-supply-order">
			<div class="order-menu">
				<ul class="layui-nav layui-nav-tree" lay-filter="test">
					<li class="layui-nav-item layui-nav-itemed">
						<a href="javascript:;">交易中心</a>
						<dl class="layui-nav-child">
							<dd class="layui-this"><a href="{:addon_url('supply://shop/order/lists')}">我的订单</a></dd>
							<dd><a href="{:addon_url('supply://shop/orderrefund/lists')}">退款/售后</a></dd>
							<dd><a href="{:addon_url('supply://shop/purchase/purchase')}">我的求购单</a></dd>
						</dl>
					</li>
				</ul>
			</div>
			<div class="order-list refund-wrap layui-form">
				<div class="order-list-title">
					<span><a href="{:addon_url('supply://shop/order/lists')}">订单列表</a>
					</span> / <span><a href="{:addon_url('supply://shop/order/detail')}?order_id={$data['order_goods_info']['order_id']}">订单详情</a>
					</span> / <span>退款</span>
				</div>

				<div class="goods-list">
					<table>
						<tr>
							<td width="62.5%">商品</td>
							<td width="12.5%">数量</td>
							<td width="12.5%">金额</td>
						</tr>
					</table>
				</div>

				<div class="goods-list">
					<table>
						<tr>
							<td width="62.5%">
								<div class="ns-table-title">
									<div class="ns-title-pic">
										<a href="{:addon_url('supply://shop/goods/detail')}?sku_id={$data['order_goods_info']['sku_id']}" target="_blank">
											<img src="{:img($data.order_goods_info.sku_image)}" alt="" onerror="this.src = 'SHOP_SUPPLY_LOCAL_IMG/default_goods.png' ">
										</a>
									</div>
									<div class="ns-title-content">
										<a href="{:addon_url('supply://shop/goods/detail')}?sku_id={$data['order_goods_info']['sku_id']}" target="_blank">
											<div class="goods-name">{$data.order_goods_info.sku_name}</div>
										</a>
									</div>
								</div>
							</td>
							<td width="12.5%" class="goods-num">{$data.order_goods_info.num}</td>
							<td width="12.5%" class="goods-money">￥{$data.order_goods_info.goods_money}</td>
						</tr>
					</table>
				</div>

				<!--退款类型 -->
				<div class="item-block">
					<div class="block-text">退款类型</div>

					<div class="pay-type-list">
						<div class="pay-type-item active" data-refund_type="1">退款无需退货</div>
						{if count($data.refund_type) == 2}
						<div class="pay-type-item" data-refund_type="2">退货退款</div>
						{/if}
						<div class="clear"></div>
						<input type="hidden" value="1" name="refund_type" />
					</div>
				</div>

				<!--退款填写-->
				<div class="item-block">
					<div class="block-text"></div>

					<div class="form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label">退款金额：</label>
							<div class="layui-input-block">
								<input type="text" name="" disabled class="layui-input" value="{$data.refund_money}">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">退款原因：</label>
							<div class="layui-input-block">
								<select name="refund_reason" lay-filter="" lay-verify="required">
									<option value="">请选择</option>
									{foreach $data.refund_reason_type as $reason_k => $reason_v}
									<option value="{$reason_v}">{$reason_v}</option>
									{/foreach}
								</select>
							</div>
						</div>

						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label">退款说明：</label>
							<div class="layui-input-block">
								<textarea placeholder="请输入退款说明（选填）" name="refund_remark" class="layui-textarea"></textarea>
							</div>
						</div>
					</div>
				</div>

				<input type="hidden" value="{$data.order_goods_info.order_goods_id}" name="order_goods_id" >

				<div class="item-block">
					<div class="order-submit">
						<button class="layui-btn ns-bg-color" lay-submit lay-filter="submit">提交</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}

{block name="script"}
<script>
	layui.use(['form'], function () {
		var form = layui.form, repeat_flag = false;
		form.render();

		$(".pay-type-item").click(function () {
			if (!$(this).hasClass("active")) {
				$(this).addClass("active");
				$(this).siblings().removeClass("active");
				$("input[name='refund_type']").val($(this).attr("data-refund_type"));
			}
		});

		form.on('submit(submit)', function(data) {
			if (repeat_flag) return;
			repeat_flag = true;

			$.ajax({
				type: 'POST',
				dataType: 'JSON',
				async: false,
				data: data.field,
				url: ns.url("supply://shop/orderrefund/refund"),
				success: function (res) {
					repeat_flag = false;
					if(checkLogin(res)) {
						if (res.code == 0) {
							location.href = ns.url("supply://shop/orderrefund/detail", {"order_goods_id": $("input[name='order_goods_id']").val()});
						}
					}
				}
			});
		})
	})
</script>
{/block}